//
//  XMRefuseRefundReasonView.m
//  XMJJ_zmy
//
//  Created by 丁浩 on 2025/7/9.
//

#import "XMRefuseRefundReasonView.h"

@interface XMRefuseRefundReasonView ()

@property (nonatomic, strong) UITextView *contentTextView;

@property (nonatomic, strong) UILabel *placeHolderLabel;

@end

@implementation XMRefuseRefundReasonView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self creatUI];
    }
    return self;
}

- (void)creatUI {
    self.backgroundColor = kColorHEXA(0x464646, 0.46);
    
    UIView *contentView = [[UIView alloc] initWithFrame:CGRectMake(0, self.height - KScaleWidth(331.0)/3, self.width, KScaleWidth(331.0))];
    contentView.backgroundColor = kColorHEX(0xffffff);
    [contentView setCornerRadius:KScaleWidth(12.0)];
    [self addSubview:contentView];
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, KScaleWidth(39.0), self.width, KScaleWidth(25.0)) font:KFontSize(18.0) textColor:kColorHEX(0x333333) textAlignment:NSTextAlignmentCenter];
    titleLabel.text = @"拒绝退款";
    [contentView addSubview:titleLabel];
    
    [contentView addSubview:self.contentTextView];
    [_contentTextView addSubview:self.placeHolderLabel];
    
    UIButton *confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom font:KBoldFontSize(14.0) frame:CGRectMake((contentView.width - KScaleWidth(120.0))/2, _contentTextView.maxY + KScaleWidth(40.0), KScaleWidth(120.0), KScaleWidth(38.0)) title:@"确认" titleColor:kColorHEX(0x333333)];
    [confirmBtn setGradientLayerWithLocations:@[@(0), @(1.0)] colors:@[(__bridge id)kColorHEX(0xFFD800).CGColor, (__bridge id)kColorHEX(0xFFE44E).CGColor] startPoint:CGPointMake(0.5, 0.37) endPoint:CGPointMake(0.03, 0.37)];
    [confirmBtn addTarget:self action:@selector(confirmAction:) forControlEvents:UIControlEventTouchUpInside];
    [contentView addSubview:confirmBtn];
    self.alpha = 0;
}

- (void)confirmAction:(UIButton *)button {
    if (_contentTextView.text.length < 10) {
        [MBProgressHUD showError:@"字数不能少于10个"];
        return;
    }
    self.confirmBlock ? self.confirmBlock(self.contentTextView.text) : nil;
}

- (void)show {
    XMWeakSelf;
    [UIView animateWithDuration:.3 animations:^{
        weakSelf.alpha = 1;
    }];
}

- (void)disMiss {
    XMWeakSelf;
    [UIView animateWithDuration:.3 animations:^{
        weakSelf.alpha = 0;
    } completion:^(BOOL finished) {
        [weakSelf removeFromSuperview];
    }];
}

- (UITextView *)contentTextView {
    if (!_contentTextView) {
        _contentTextView = [[UITextView alloc] initWithFrame:CGRectMake(KScaleWidth(28.0), KScaleWidth(95.0), self.width - KScaleWidth(28.0)*2, KScaleWidth(120.0))];
        _contentTextView.backgroundColor = kColorHEX(0xEDEDEE);
        [_contentTextView setCornerRadius:KScaleWidth(10.0)];
        _contentTextView.contentInset = UIEdgeInsetsMake(KScaleWidth(18.0), KScaleWidth(18.0), KScaleWidth(18.0), KScaleWidth(18.0));
    }
    return _contentTextView;
}

- (UILabel *)placeHolderLabel {
    if (!_placeHolderLabel) {
        _placeHolderLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.contentTextView.width, KScaleWidth(23.0)) font:KFontSize(14.0) textColor:kColorHEX(0x999999)];
        _placeHolderLabel.text = @"请输入拒绝理由（不少于10个字）";
        _placeHolderLabel.userInteractionEnabled = NO;
    }
    return _placeHolderLabel;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
